package and.process;

import java.util.Date;

import and.common.MyCommon;

public class CreateNumProcess {
	private StatisticsProcess statisticsProcess = new StatisticsProcess();
	public String createTodayNum(int length,int to){
		StringBuilder result = new StringBuilder();
		int temp;
		int tempLast =0;
		String[] mostNums = statisticsProcess.getMostNum().split("\n");
		int start = new Date().getDay();
		start =length - start<length?length - start:0;
		start = start>=0?start:0;
		for(int i=start;i<length+start;i++){
			temp =to - Integer.parseInt(mostNums[i].split("=")[0]);
			if(i!=length+start-1){
				if(i==length+start-2 && MyCommon.QueryName.equals(MyCommon.TCDALETOU) && temp>12){
					if(tempLast ==0 ||tempLast !=temp/2){
						result.append(temp/2);
						result.append(" ");
					}else{
						if(tempLast>1){
							result.append(tempLast-1);
							result.append(" ");
						}else{
							result.append(tempLast+1);
							result.append(" ");
						}
					}
					tempLast = temp/2;
				}else{
					result.append(temp);
					result.append(" ");
					tempLast = temp;
				}
			}else{
				if(MyCommon.QueryName.equals(MyCommon.FCSHUANGSEQIU) && temp>16){
					result.append(temp/2); 
				}else if(MyCommon.QueryName.equals(MyCommon.TCDALETOU) && temp>12){
					temp = temp/2-5;
					if(tempLast ==0 ||tempLast !=temp){
						result.append(temp);
					}else{
						if(tempLast>1){
							result.append(tempLast-1);
						}else{
							result.append(tempLast+1);
						}
					}
				}else {
					result.append(temp);
				}
			}
			
		}
		
		return result.toString();
	}
	
	public String createRandomNum(int length,int from,int to){
		StringBuilder result = new StringBuilder();
		int temp;
		for(int i=0;i<length;i++){
			temp = createRandomNewNum(from,to,null);
			result.append(temp);
			if(i!=length-1){
				result.append(" "); 
			}
		}
		return result.toString();
	}
	
	public String createRandomUniqueNum(int length,int from,int to){
		StringBuilder result = new StringBuilder();
		int[] nums=new int[length];
		int temp;
		for(int i=0;i<length;i++){
			temp = createRandomNewNum(from,to,nums);
			result.append(temp); 
			nums[i] = temp;
			if(i!=length-1){
				result.append(" "); 
			}
		}
		return result.toString();
	}
	
	private int createRandomNewNum(int from,int to,int[] oldNums){
		boolean flag = true;
		int result = 0;
		while(flag){
			result = (int)(Math.random()* to)+from;
			flag =false;
			if(oldNums!=null){
				for(int i=0;i<oldNums.length;i++){
					if(oldNums[i]==result){
						flag = true;
					}
				}
			}
		}
		return result;
	}
	
	public static void main(String[] args) {
		new CreateNumProcess().createRandomUniqueNum(7,1,30);
	}
}
